package com.bjfu.nlp.controller;

import com.bjfu.common_util.R;
import com.bjfu.nlp.service.NlpService;
import com.bjfu.nlp.utils.HttpClientUtils;
import com.bjfu.nlp.vo.ResultVo;
import com.bjfu.nlp.vo.textSegmentationVo;
import com.bjfu.servicebase.exceptionHandler.CommonException;
import com.google.gson.Gson;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Description;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/nlpservice")
public class NlpController {
    @Autowired
    private NlpService nlpService;

    @PostMapping("seg/dl/")
    @ApiOperation("深度学习方法的分词接口")
    @Description("可以并行处理多段文本")
    public R textSegmentation(@RequestBody @Validated textSegmentationVo vo) throws Exception {
        if(StringUtils.isEmpty(vo.getUrl()) || StringUtils.isEmpty( vo.getToken()) || vo.getTextList()==null || vo.getTextList().isEmpty()){
            throw new CommonException(20001,"请求参数不完整");
        }
        List<ResultVo> result = nlpService.textSegmentation(vo);

        return R.ok().data("wordFrequent",result);
    }
}
